package com.ilancuo.thinkinjava;

/** 在构造器中调用方法可能会存在问题
 *
 * Created by ilancuo on 12/03/2017.
 */
class Glyph {
    void draw() {
        System.out.println("Glyph draw()");
    }

    Glyph() {
        System.out.println("Glyph before draw()");
        draw();
        System.out.println("Glyph after draw()");
    }
}

class RoundGlyph extends Glyph {
    private int radius = 1;
    RoundGlyph(int r) {
        radius = r;
        System.out.println("RoundGlyph.RoundGlyph(), radius = " + radius);
    }

    @Override
    void draw() {
        System.out.println("RoundGlyph.draw(), radius = " + radius);
    }
}

public class PolyConstructors {
    public static void main(String[] args) {
        new RoundGlyph(5);
    }
}
/**
 * out:
 * Glyph before draw()
 * RoundGlyph.draw(), radius = 0 //此处的radius还未进行初始化,原因:子类对象还没有创建,未初始化
 * Glyph after draw()
 * RoundGlyph.RoundGlyph(), radius = 5
 */
